package Q5;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.Socket;

public class User implements Serializable {


    private static final long serialVersionUID = 7773154921402628140L;

    private final Socket client;
    private InetAddress name;
    private ObjectOutputStream send;
    private ObjectInputStream receive;

    public User(Socket client, InetAddress name) {
        this.client = client;
        this.name = name;
        try {
            this.send = new ObjectOutputStream(client.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            this.receive = new ObjectInputStream(client.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public InetAddress getName() {
        name = client.getInetAddress();
        return name;
    }


    public Socket getClient() {
        return client;
    }

    public ObjectOutputStream getSend() {
        return send;
    }

    public ObjectInputStream getReceive() {
        return receive;
    }

    @Override
    public String toString() {
        return "用户"+ getName();
    }
}
